package com.ykh.mybbsdemo.handler;

import com.ykh.mybbsdemo.dao.pojo.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-08-30
 * Time: 18:19
 */
//对加了ControllerAdvice注解的方法进行拦截处理. AOP的实现
@ControllerAdvice
public class AllExceptionHandler {
    //进行异常处理, 处理Exception.class的异常
    @ExceptionHandler(Exception.class)
    //让返回的数据时josn数据
    @ResponseBody
    public Result doException(Exception ex) {
        ex.printStackTrace();
        return Result.fail(-999,"系统异常");
    }
}
